package hibernate_many2many;

import hibernate_many2many.hib.Department;
import hibernate_many2many.hib.Emp;
import hibernate_many2many.hib.HibernateSessionFactory;
import hibernate_many2many.hib.Interesting;

import java.util.Set;

import org.hibernate.Session;
import org.hibernate.Transaction;


public class Main {

	public static void main(String[] args) {
		Session session=HibernateSessionFactory.getSession();
		Transaction tx=session.beginTransaction();//insert update delete
		Emp emp=new Emp();
		emp.setName("Carl Ultraman");
		emp.setSex("女");
		Department department=(Department) session.get(Department.class, 2);//select department
		emp.setDepartment(department);
		
		Set interestings=emp.getInterestings();
		Interesting in1=(Interesting) session.get(Interesting.class,1);//select interestin
		interestings.add(in1);
		Interesting in2=(Interesting) session.get(Interesting.class,2);//select interestin
		interestings.add(in2);
		
		emp.setInterestings(interestings);
		
		session.save(emp);//insert into empdb.emp; �����м��2��δ���룡
		tx.commit();
		session.close();

	}

}
